﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Windows;
using System.Windows.Controls;

namespace DesktopInfo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        CompositionContainer pluginsManager;

        [ImportMany(typeof(IDesktopInfoPlugin))]
        private IList<IDesktopInfoPlugin> plugins { get; set; }


        public MainWindow()
        {
            InitializeComponent();

            this.Closed += new System.EventHandler(MainWindow_Closed);
            plugins = new List<IDesktopInfoPlugin>();
            LoadPlugins();
        }

       


        void MainWindow_Closed(object sender, System.EventArgs e)
        {

        }

        private void LoadPlugins()
        {
            DirectoryCatalog appDir = new DirectoryCatalog(@"d:\plugins");

            pluginsManager = new CompositionContainer(appDir);
            pluginsManager.ComposeParts(this);


            foreach (var plugin in plugins)
            {
                try
                {
                    gadgets.Children.Add((UserControl)plugin);

                }
                catch (Exception ex)
                {
                    
                    
                }

                

            }
        }

       

    }
}
